/**
 * elancom Corporation copy right 2012 - 2015  
 *   
 * $Header: https://192.168.1.224/svn/elancom/product/elancom-platform/trunk/src/main/java/com/elancom/framework/commons/json/serializer/PointSerializer.java 1034 2012-07-02 03:09:12Z lanzhouxue $
 * $Id: PointSerializer.java 1034 2012-07-02 03:09:12Z lanzhouxue $
 * $Author: lanzhouxue $
 * $Date: 2012-07-02 11:09:12 +0800 (Mon, 02 Jul 2012) $
 * $Revision: 1034 $
 */
package com.elancom.framework.commons.json.serializer;

import java.awt.Point;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.Collections;
import java.util.Set;

public class PointSerializer implements AutowiredObjectSerializer {

	public final static PointSerializer instance = new PointSerializer();

	@Override
	public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType) throws IOException {
		final SerializeWriter out = serializer.getWriter();
		final Point font = (Point) object;
		if (font == null) {
			out.writeNull();
			return;
		}

		char sep = '{';
		if (out.isEnabled(SerializerFeature.WriteClassName)) {
			out.write('{');
			out.writeFieldName("@type");
			out.writeString(Point.class.getName());
			sep = ',';
		}

		out.writeFieldValue(sep, "x", font.getX());
		out.writeFieldValue(',', "y", font.getY());
		out.write('}');

	}

	@Override
	public Set<Type> getAutowiredFor() {
		return Collections.<Type> singleton(Point.class);
	}
}
